/* reoprp41.p - PRODUCTIVITY BY ITEM REPORT                                   */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: reoprp41.p 2366 2010-11-10 01:47:19Z zzh                          $: */
/* $Revision: 1.12.1.7 $                                                      */
/*V8:ConvertMode=FullGUIReport                                                */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/01/95   BY: WUG *G0G3*                */
/* REVISION: 8.6      LAST MODIFIED: 10/10/97   BY: bvm *K0RX*                */
/* REVISION: 8.6      LAST MODIFIED: 11/18/97   BY: bvm *K19V*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 06/08/98   BY: *J2NB* A. Licha           */
/* REVISION: 8.6E     LAST MODIFIED: 07/17/98   BY: *L047* Santhosh Nair      */
/* REVISION: 8.6E     LAST MODIFIED: 10/12/98   BY: *L0BY* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb                  */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *GA37*                    */
/* Revision: 1.12.1.3     BY: Hualin Zhong     DATE: 05/30/01   ECO: *N0YY*   */
/* Revision: 1.12.1.4     BY: Manisha Sawant   DATE: 08/20/01   ECO: *P01N*   */
/* Revision: 1.12.1.5  BY: Amit Chaturvedi DATE: 03/08/02 ECO: *N1CB* */
/* Revision: 1.12.1.7.3.1  BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00K* */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */
{us/mf/mfdtitle.i "99 "}
{us/wo/woconsdf.i}

define  variable altpart          like ptal_alt_part no-undo.
define  variable altpart1         like ptal_alt_part no-undo.
define variable emp              like op_emp     no-undo.
define variable emp1             like op_emp     no-undo.
define variable part             like op_part    no-undo.
define variable part1            like op_part    no-undo.
define variable wkctr            like op_wkctr   no-undo.
define variable wkctr1           like op_wkctr   no-undo.
define variable mach             like op_mch     no-undo.
define variable mach1            like op_mch     no-undo.
define variable opdate           like op_date    no-undo.
define variable opdate1          like op_date    no-undo.
define variable run_var          like wr_run     format "->>9.999"      no-undo.
define variable setup_var        like wr_setup   format "->>9.999"      no-undo.
define variable run_eff          like wr_run     format ">>>9.99%"      no-undo.
define variable setup_eff        like run_eff    no-undo.
define variable desc1            like pt_desc1   no-undo.
define variable setup_per        like wr_setup   no-undo.
define variable std_run          like wr_run     label "Std Run"  no-undo.
define variable tot_hours        as   decimal    label "Tot Hrs"
   format "->,>>9.9"      no-undo.
define variable std_hours        like tot_hours  label "Std Hrs"  no-undo.
define variable prod_hours       like tot_hours  label "Prod Hrs" no-undo.
define variable down_hours       like tot_hours  label "Down Hrs" no-undo.
define variable achvd_rate       as   integer    label "Act Rate" no-undo.
define variable pcs_comp         like achvd_rate label "Pcs Proc"  no-undo.
define variable std_rate         as   integer    label "Std Rate"
   format "->>>,>>9"      no-undo.
define variable shift            like op_shift   no-undo.
define variable detail           like mfc_logical label "Report Format"
   format "Detail/Summary"
   initial yes            no-undo.
define variable include_nonmilestone like mfc_logical
   label "Include Nonmilestone Operations" no-undo.
define variable stdhrs           as   decimal    no-undo.
define variable dwn-hours        as   decimal    no-undo.
define variable d-prod-hrs       as   decimal    no-undo.
define variable d-prod-percent   as   decimal    no-undo.
define variable d-util-percent   as   decimal    no-undo.
define variable d-attain-percent as   decimal    no-undo.
define  variable order_type_key  like lngd_key1 initial "0" no-undo.
define  variable c-lngd-dataset like lngd_det.lngd_dataset
   initial "wo_mstr" no-undo.
define variable orderType as character format "x(9)" label "Include Repetitive/Discrete/Both" no-undo.

form
   part      colon 15      part1     label "To" colon 49
   emp       colon 15      emp1      label "To" colon 49
   opdate    colon 15      opdate1   label "To" colon 49
   wkctr     colon 15      wkctr1    label "To" colon 49
   mach      colon 15      mach1     label "To" colon 49
   altpart   colon 15 label "Alt Item ID" altpart1  label "To" colon 49
   shift     colon 15
   skip (1)
   detail    colon 35
   include_nonmilestone colon 35
   orderType colon 35 skip
with frame a side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

for first lngd_det where lngd_dataset = c-lngd-dataset
   and lngd_field   = "orderType"
   and lngd_lang    = global_user_lang
   and lngd_key1    = order_type_key
no-lock:
end.

if available lngd_det then
   orderType = lngd_key2.
else
   orderType = "".

{us/wb/wbrp01.i}

repeat:
   if part1   = hi_char  then part1   = "".
   if wkctr1  = hi_char  then wkctr1  = "".
   if mach1   = hi_char  then mach1   = "".
   if emp1    = hi_char  then emp1    = "".
   if opdate  = low_date then opdate  = ?.
   if opdate1 = hi_date  then opdate1 = ?.
   if altpart1   = hi_char  then altpart1  = "".

   if c-application-mode <> 'web'
      then
   update part
      part1
      emp
      emp1
      opdate
      opdate1
      wkctr
      wkctr1
      mach
      mach1
      altpart
      altpart1
      shift
      detail
      include_nonmilestone
      orderType
   with frame a

      editing:
      if frame-field = "orderType" then do:
         {us/mf/mfnp05.i lngd_det lngd_det
            "lngd_dataset   = c-lngd-dataset
              and lngd_field  = 'orderType'
              and lngd_lang   = global_user_lang"
            lngd_key2 "input orderType" }
         if recno <> ? then
         display lngd_key2 @ orderType
         with frame a.
      end.
      else do:
         status input.
         readkey.
         apply lastkey.
      end.

   end.

   /* INCLUDE FILE FOR WEB-ENABLEMENT */
   {us/wb/wbrp06.i &command = update
      &fields  = "part   part1   emp   emp1
        opdate opdate1 wkctr wkctr1
        mach   mach1 altpart altpart1  shift detail
        include_nonmilestone orderType"
      &frm     = "a"}

   if  (c-application-mode <> 'web')
      or  (c-application-mode =  'web'
      and (c-web-request begins  'data'))
   then do:

      if part1   = "" then part1   = hi_char.
      if wkctr1  = "" then wkctr1  = hi_char.
      if mach1   = "" then mach1   = hi_char.
      if emp1    = "" then emp1    = hi_char.
      if opdate  = ?  then opdate  = low_date.
      if opdate1 = ?  then opdate1 = hi_date.
      if altpart1 = "" then altpart1  = hi_char.

      bcdparm = "".
      {us/bbi/gprun.i ""gpquote.p""
         "(input-output bcdparm,16,
           part,part1,emp,emp1,string(opdate),string(opdate1),
           wkctr,wkctr1,mach,mach1,altpart,altpart1,shift,string(detail),
           string(include_nonmilestone),
           orderType,null_char,null_char,null_char,
           null_char)"}

   end. /* IF c-application-mode <> 'web' */

   for first lngd_det where
      lngd_dataset     = c-lngd-dataset
      and lngd_field       = "orderType"
      and lngd_lang        = global_user_lang
      and lngd_key2 = orderType
   no-lock:
   end.
   if not available lngd_det
   then do:

      /* MUST BE (S)cheduled or (D)iscrete or (B)oth */
      {us/bbi/pxmsg.i &MSGNUM=10346 &ERRORLEVEL=4}

      if c-application-mode = "WEB"
         then
         return.

      else
      next-prompt
         orderType with frame a.
      undo,retry.
   end.
   order_type_key=lngd_key1.

   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType                = "printer"
      &printWidth               = 132
      &pagedFlag                = " "
      &stream                   = " "
      &appendToFile             = " "
      &streamedOutputToTerminal = " "
      &withBatchOption          = "yes"
      &displayStatementType     = 1
      &withCancelMessage        = "yes"
      &pageBottomMargin         = 6
      &withEmail                = "yes"
      &withWinprint             = "yes"
      &defineVariables          = "yes"}

   /* TO PRINT PAGE HEADING */
   {us/bbi/mfphead.i}

   if shift > ""
   then do:

      form header
         getTermLabel("SHIFT",10) + ": " + shift at 61 format "x(14)"
      with frame shift width 132 page-top.
      view frame shift.

   end. /* IF shift > "" */

   for each op_hist
         where op_hist.op_domain = global_domain and (  (op_part      >= part
         and    op_part      <= part1)
         and    op_site       = op_site
         and    op_wo_op      = op_wo_op
         and   (op_date      >= opdate
         and    op_date      <= opdate1)
         and   (op_emp       >= emp
         and    op_emp       <= emp1)
         and   (op_wkctr     >= wkctr
         and    op_wkctr     <= wkctr1)
         and   (op_mch       >= mach
         and    op_mch       <= mach1)
         and   (op_shift      = shift
         or     shift         = "")
         and   (op_qty_comp  <> 0
         or     op_act_run   <> 0
         or     op_act_setup <> 0)
         and   (include_nonmilestone
         or     op_milestone)
         and    op_type      <> "DOWN"
         )
         and ((altpart = "" and altpart1 = hi_char)
         or can-find(first ptal_mstr where ptal_mstr.ptal_domain = global_domain
         and ptal_part             = op_part
         and ptal_alt_part         >= altpart
         and ptal_alt_part         <= altpart1
         and ptal_active))
         and (order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE}
         or can-find(first wo_mstr where wo_mstr.wo_domain = global_domain
         and wo_lot            = op_wo_lot
         and (wo_type= order_type_key)))
      no-lock
         break by op_part
         by op_wo_op
         by op_date
         by op_wkctr
         by op_emp
      with frame b down width 132:

      find first ptal_mstr where ptal_mstr.ptal_domain = global_domain
         and ptal_part             = op_part
         and ptal_active
      no-lock no-error.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).

      if c-application-mode <> 'web'
         then
         view frame phead.

      if first-of(op_wo_op)
      then do:

         if page-size - line-counter < 8
            then
            page.

         display.

         if first-of (op_part)
            or detail
         then do:

            put {us/bbi/gplblfmt.i &FUNC=getTermLabel(""ITEM_NUMBER"",15)
               &CONCAT="': '"} op_part.
            for first pt_mstr
               where pt_mstr.pt_domain = global_domain and  pt_part = op_part
            no-lock:
            put " " pt_desc1 + " " + pt_desc2 format "x(50)" skip.
            end. /* FOR FIRST pt_mstr */

         end. /* IF FIRST-OF (op_part) OR detail */

         put {us/bbi/gplblfmt.i &FUNC=getTermLabel(""ALT_NUMBER"",15)
            &CONCAT="': '"}
            if available(ptal_mstr) then ptal_alt_part else fill(' ',18) format "x(28)" skip.

         for first wr_route
            where wr_route.wr_domain = global_domain and  wr_lot = op_wo_lot
            and   wr_op  = op_wo_op
         no-lock:

         put getTermLabelRtColon("OPERATION",12) + " " +
            string(wr_op) + "   " + wr_desc format "x(44)".

         end. /* FOR FIRST wr_route */

         if detail
            then
            put skip(1).

      end. /* IF FIRST-OF(op_wo_op) */

      prod_hours = 0.
      if op_type   <> "DOWNTIME"
         then
         prod_hours = op_act_run.

      down_hours = 0.
      if op_type = "DOWNTIME"
         then
   down_hours = op_act_run.

      std_hours = op_std_run * op_qty_comp.

      accumulate op_qty_comp (total by op_wkctr).
      accumulate prod_hours  (total by op_wkctr).
      accumulate down_hours  (total by op_wkctr).
      accumulate std_hours   (total by op_wkctr).

      accumulate prod_hours  (total by op_wo_op).
      accumulate down_hours  (total by op_wo_op).
      accumulate std_hours   (total by op_wo_op).

      accumulate prod_hours  (total by op_part).
      accumulate down_hours  (total by op_part).
      accumulate std_hours   (total by op_part).

      if last-of(op_wkctr)
      then do:

         assign
            tot_hours  = (accum sub-total by op_wkctr prod_hours)
            + (accum sub-total by op_wkctr down_hours)
            pcs_comp   = accum sub-total by op_wkctr op_qty_comp
            achvd_rate = 0.

         if (accum sub-total by op_wkctr prod_hours) <> 0
            then
            achvd_rate = pcs_comp / (accum sub-total by op_wkctr prod_hours).

         std_rate = 0.
         if (accum sub-total by op_wkctr std_hours) <> 0
            then
            std_rate = pcs_comp / (accum sub-total by op_wkctr std_hours).

         if page-size - line-counter < 2
            then
            page.

         if detail
         then do:

            assign
               stdhrs           = (accum sub-total by op_wkctr std_hours)
               dwn-hours        = (accum sub-total by op_wkctr down_hours)
               d-prod-hrs       = (accum sub-total by op_wkctr prod_hours)
               d-prod-percent   = 100 * (accum sub-total by op_wkctr std_hours)
               / (accum sub-total by op_wkctr prod_hours)
               d-util-percent   = 100 * (accum sub-total by op_wkctr prod_hours)
               / tot_hours
               d-attain-percent = 100 * (accum sub-total by op_wkctr std_hours)
               / tot_hours.

            display
               space(4)
               op_wkctr
               pcs_comp
               std_rate
               achvd_rate
               stdhrs           label "Std Hrs"  format "->,>>9.9"
               tot_hours
               dwn-hours        label "Down Hrs" format "->,>>9.9"
               d-prod-hrs       label "Prod Hrs" format "->,>>9.9"
               d-prod-percent   label "Prod %" format "->>9.9"
               space(2)
               d-util-percent   label "Util %"  format "->>9.9"
               d-attain-percent label "Attain %" format "->>9.9"
               space(2)
               op_date          label "  Date".

         end. /* IF detail */

         accumulate tot_hours (total by op_wo_op).
         accumulate tot_hours (total by op_part).

      end. /* IF LAST-OF(op_wkctr) */

      if last-of (op_wo_op)
      then do:

         if detail
            then
         put {us/bbi/gplblfmt.i &FUNC=getTermLabel(""OPERATION_TOTAL"",25)
            &CONCAT="':'"} to 43 space(1).

         put
            (accum sub-total by op_wo_op std_hours)  format "->,>>9.9" to 52
            (accum sub-total by op_wo_op tot_hours)  format "->,>>9.9" to 61
            (accum sub-total by op_wo_op down_hours) format "->,>>9.9" to 70
            (accum sub-total by op_wo_op prod_hours) format "->,>>9.9" to 79
            100 * (accum sub-total by op_wo_op std_hours)
            / (accum sub-total by op_wo_op prod_hours)
            format "->>9.9%" to 87
            100 * (accum sub-total by op_wo_op prod_hours)
            / (accum sub-total by op_wo_op tot_hours)
            format "->>9.9%" to 95
            100 * ((accum sub-total by op_wo_op std_hours)
            *  (accum sub-total by op_wo_op prod_hours))
            / ((accum sub-total by op_wo_op prod_hours)
            *  (accum sub-total by op_wo_op tot_hours))
            format "->>9.9%" to 104
            skip.

      end. /* IF LAST-OF(op_wo_op) */

      if last-of(op_part)
      then do:

         put
            skip(1)
            {us/bbi/gplblfmt.i &FUNC=getTermLabel(""ITEM_TOTAL"",25)
            &CONCAT="':'"} to 43 space(1)
            (accum sub-total by op_part std_hours)  format "->,>>9.9" to 52
            (accum sub-total by op_part tot_hours)  format "->,>>9.9" to 61
            (accum sub-total by op_part down_hours) format "->,>>9.9" to 70
            (accum sub-total by op_part prod_hours) format "->,>>9.9" to 79
            100 * (accum sub-total by op_part std_hours)
            / (accum sub-total by op_part prod_hours)
            format "->>9.9%" to 87
            100 * (accum sub-total by op_part prod_hours)
            / (accum sub-total by op_part tot_hours)
            format "->>9.9%" to 95
            100 * ((accum sub-total by op_part std_hours)
            *  (accum sub-total by op_part prod_hours))
            / ((accum sub-total by op_part prod_hours)
            *  (accum sub-total by op_part tot_hours))
            format "->>9.9%" to 104
            skip.

      end. /* IF LAST-OF(op_part) */

      if last (op_part)
      then do:

         put
            skip(1)
            {us/bbi/gplblfmt.i &FUNC=getTermLabel(""REPORT_TOTAL"",25)
            &CONCAT="':'"} to 43 space(1)
            (accum total std_hours)         format "->,>>9.9" to 52
            (accum total tot_hours)         format "->,>>9.9" to 61
            (accum total down_hours)        format "->,>>9.9" to 70
            (accum total prod_hours)        format "->,>>9.9" to 79
            100 * (accum total std_hours)
            / (accum total prod_hours)  format "->>9.9%" to 87
            100 * (accum total prod_hours)
            / (accum total tot_hours)   format "->>9.9%" to 95
            100 * ((accum total std_hours)
            *  (accum total prod_hours))
            / ((accum total prod_hours)
            *  (accum total tot_hours)) format "->>9.9%" to 104
            skip.

      end. /* IF LAST (op_part) */

      /* REPORT EXIT FOR PAGING INCLUDE FILE */
      {us/mf/mfrpchk.i}

   end. /* FOR EACH op_hist */

   /* REPORT TRAILER */
   {us/mf/mfrtrail.i}

end. /* REPEAT: */

{us/wb/wbrp04.i &frame-spec = a}

